import sys
import os

sys.path.append('/opt/agent')

from werkzeug.serving import run_simple

from api import settings

from api.apps import app

from api.utils import show_configs
from api.db.db_models import init_database_tables as init_web_db
from rag.settings import print_rag_settings
from api.plugins.client_manage import generate_plugins

PORT = 8088

if __name__ == '__main__':
    print(r"""
            ____   ___    ______ ______ __               
           / __ \ /   |  / ____// ____// /____  _      __
          / /_/ // /| | / / __ / /_   / // __ \| | /| / /
         / _, _// ___ |/ /_/ // __/  / // /_/ /| |/ |/ / 
        /_/ |_|/_/  |_|\____//_/    /_/ \____/ |__/|__/                             

        """)
    print("RAGFlow HTTP server start...")
    show_configs()
    settings.init_settings()
    print_rag_settings()
    generate_plugins()

    init_web_db()
    run_simple(
        hostname="0.0.0.0",
        port=PORT,
        application=app,
        threaded=True,
        use_reloader=False,
        use_debugger=False,
    )
